from django.db import models

class FeedItem(models.Model):
    last_modified = models.DateTimeField(auto_now=True)
    
    def show_updates(self):
	return False
    def get_appearance_date(self):
        raise NotImplementedError("get_appearance_date must be implemented in all FeedItem objects")
    def get_link(self,course):
        raise NotImplementedError("get_link must be implemented in all FeedItem objects")
    def get_title(self):
        raise NotImplementedError("get_title must be implemented in all FeedItem objects")
    def get_description(self):
        raise NotImplementedError("get_title must be implemented in all FeedItem objects")
    
    class Meta:
	abstract = True
class FeedItemCollection:
    def __init__(self):
        self.feed_items = {}
        
    def register_item(self, feed_type, classname):
	if issubclass(classname,FeedItem):
	    if not feed_type in self.feed_items:
		self.feed_items[feed_type] = []
	    self.feed_items[feed_type].append(classname)
	else:
	    raise TypeError("FeedItems can only register FeedItem-derived classes")
    def get_items(self):
        return self.feed_items
FeedItems = FeedItemCollection()